package com.fdb.efp.nls.service.impl;

import com.alibaba.fastjson.JSON;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.ColltDelayCaseRecordDao;
import com.fdb.efp.nls.service.domain.ColltDelayCaseRecord;
import com.fdb.efp.nls.service.facade.ColltDelayCaseRecordService;
import com.fdb.efp.nls.service.vo.ColltDelayCaseRecordVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 委外催收延案记录表<p>
 * @author ligm
 * @date 2019-08-27
 */
@Service("colltDelayCaseRecordService")
public class ColltDelayCaseRecordServiceImpl implements ColltDelayCaseRecordService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(ColltDelayCaseRecordServiceImpl.class);

	@Autowired
	private ColltDelayCaseRecordDao colltDelayCaseRecordDao;
	
	/**
	 * 新增操作
	 */
	public int insertColltDelayCaseRecord(ColltDelayCaseRecordVO inColltDelayCaseRecordVo) {
		logger.debug("当前新增数据为:"+ inColltDelayCaseRecordVo.toString());
		int num = 0;
		try {
			ColltDelayCaseRecord colltDelayCaseRecord = new ColltDelayCaseRecord();
			beanCopy(inColltDelayCaseRecordVo, colltDelayCaseRecord);
			num = colltDelayCaseRecordDao.insertColltDelayCaseRecord(colltDelayCaseRecord);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(ColltDelayCaseRecordVO inColltDelayCaseRecordVo) {
		logger.debug("当前删除数据条件为:"+ inColltDelayCaseRecordVo);
		int num = 0;
		try {
			ColltDelayCaseRecord colltDelayCaseRecord = new ColltDelayCaseRecord();
			beanCopy(inColltDelayCaseRecordVo, colltDelayCaseRecord);
			num = colltDelayCaseRecordDao.deleteByPk(colltDelayCaseRecord);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inColltDelayCaseRecordVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(ColltDelayCaseRecordVO inColltDelayCaseRecordVo) {
		logger.debug("当前修改数据为:"+ inColltDelayCaseRecordVo.toString());
		int num = 0;
		try {
			ColltDelayCaseRecord colltDelayCaseRecord = new ColltDelayCaseRecord();
			beanCopy(inColltDelayCaseRecordVo, colltDelayCaseRecord);
			num = colltDelayCaseRecordDao.updateByPk(colltDelayCaseRecord);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inColltDelayCaseRecordVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public ColltDelayCaseRecordVO queryByPk(ColltDelayCaseRecordVO inColltDelayCaseRecordVo) {
		
		logger.debug("当前查询参数信息为:"+ inColltDelayCaseRecordVo);
		try {
			ColltDelayCaseRecord queryColltDelayCaseRecord = new ColltDelayCaseRecord();
			beanCopy(inColltDelayCaseRecordVo, queryColltDelayCaseRecord);
			ColltDelayCaseRecord queryRslColltDelayCaseRecord = colltDelayCaseRecordDao.queryByPk(queryColltDelayCaseRecord);
			if (Objects.nonNull(queryRslColltDelayCaseRecord)) {
				ColltDelayCaseRecordVO outColltDelayCaseRecordVo = beanCopy(queryRslColltDelayCaseRecord, new ColltDelayCaseRecordVO());
				logger.debug("当前查询结果为:"+ outColltDelayCaseRecordVo.toString());
				return outColltDelayCaseRecordVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public int insertVoBatch(List<ColltDelayCaseRecordVO> delayCaseRecordVOList) {
		logger.debug("当前新增数据条数为:"+ delayCaseRecordVOList.size());
		List<ColltDelayCaseRecord> colltDelayCaseRecords = new ArrayList<ColltDelayCaseRecord>();
		int num = 0;
		try {
			colltDelayCaseRecords = (List<ColltDelayCaseRecord>)beansCopy(delayCaseRecordVOList, ColltDelayCaseRecord.class);
			num = colltDelayCaseRecordDao.insertVoBatch(colltDelayCaseRecords);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<ColltDelayCaseRecordVO> queryAllOwner(ColltDelayCaseRecordVO colltDelayCaseRecordVo) {
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<ColltDelayCaseRecordVO> list = null;
		try {
			List<ColltDelayCaseRecord> colltDelayCaseRecords = colltDelayCaseRecordDao.queryAllOwnerByPage(colltDelayCaseRecordVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ colltDelayCaseRecords.size());
			pageSet(colltDelayCaseRecords, colltDelayCaseRecordVo);
			list = (List<ColltDelayCaseRecordVO>) beansCopy(colltDelayCaseRecords, ColltDelayCaseRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<ColltDelayCaseRecordVO> queryAllCurrOrg(ColltDelayCaseRecordVO colltDelayCaseRecordVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<ColltDelayCaseRecord> colltDelayCaseRecords = colltDelayCaseRecordDao.queryAllCurrOrgByPage(colltDelayCaseRecordVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+colltDelayCaseRecords.size());
		List<ColltDelayCaseRecordVO> list = null;
		try {
			pageSet(colltDelayCaseRecords, colltDelayCaseRecordVo);
			list = (List<ColltDelayCaseRecordVO>) beansCopy(colltDelayCaseRecords, ColltDelayCaseRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<ColltDelayCaseRecordVO> queryAllCurrDownOrg(ColltDelayCaseRecordVO colltDelayCaseRecordVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<ColltDelayCaseRecord> colltDelayCaseRecords = colltDelayCaseRecordDao.queryAllCurrDownOrgByPage(colltDelayCaseRecordVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ colltDelayCaseRecords.size());
		List<ColltDelayCaseRecordVO> list = null;
		try {
			pageSet(colltDelayCaseRecords, colltDelayCaseRecordVo);
			list = (List<ColltDelayCaseRecordVO>) beansCopy(colltDelayCaseRecords, ColltDelayCaseRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public int deleteByDelayCaseAppSerno(String delayCaseAppSerno) {
		logger.debug("根据委外延案申请流水号:"+ delayCaseAppSerno);
		int num = 0;
		try {
			num = colltDelayCaseRecordDao.deleteByDelayCaseAppSerno(delayCaseAppSerno);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据委外延案申请流水号:"+ delayCaseAppSerno +"删除的数据条数为"+ num);
		return num;
	}

	@Override
	public List<ColltDelayCaseRecordVO> queryByDelayCaseRecords(ColltDelayCaseRecordVO colltDelayCaseRecordVo) {
		List<ColltDelayCaseRecordVO> list = null;
		logger.debug("根据条件查询信息开始，入参为：" + JSON.toJSONString(colltDelayCaseRecordVo));
		ColltDelayCaseRecord queryColltDelayCaseRecord = new ColltDelayCaseRecord();
		beanCopy(colltDelayCaseRecordVo, queryColltDelayCaseRecord);
		List<ColltDelayCaseRecord> colltDelayCaseRecords = colltDelayCaseRecordDao.queryByDelayCaseRecords(queryColltDelayCaseRecord);
		logger.debug("根据条件查询到的结果集数量为:"+ colltDelayCaseRecords.size());
		try {
			list = (List<ColltDelayCaseRecordVO>) beansCopy(colltDelayCaseRecords, ColltDelayCaseRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public int deleteOneVO(ColltDelayCaseRecordVO colltDelayCaseRecordVO) {
		logger.debug("删除数据的参数为:"+ colltDelayCaseRecordVO.toString());
		int num = 0;
		try {
			ColltDelayCaseRecord colltDelayCaseRecord = beanCopy(colltDelayCaseRecordVO, new ColltDelayCaseRecord());
			num = colltDelayCaseRecordDao.deleteOneDomain(colltDelayCaseRecord);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据参数删除的数据条数为"+ num);
		return num;
	}

	@Override
	public List<ColltDelayCaseRecordVO> queryByDCR(String delayCaseAppSerno){
		List<ColltDelayCaseRecordVO> list = null;
		logger.debug("根据条件查询信息开始，入参为：" + delayCaseAppSerno);
		List<ColltDelayCaseRecord> colltDelayCaseRecords = colltDelayCaseRecordDao.queryByDCR(delayCaseAppSerno);
		logger.debug("根据条件查询到的结果集数量为:"+ colltDelayCaseRecords.size());
		try {
			list = (List<ColltDelayCaseRecordVO>) beansCopy(colltDelayCaseRecords, ColltDelayCaseRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}
}
